﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QLTV.Public;
using System.Data.SqlClient;

namespace QLTV.DAL
{
    public class DauSachDAL
    {
        ConnectionData connect;
        //Chưa dùng
        public DataTable DauSach_LoadDuLieu()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("DAUSACH_LOAD");
            }
            catch(SqlException ex)
            {
                throw ex;
            }
        }
        //Chưa dùng
        public DataTable DauSach_LoadMaDauSach(DauSachDTO p)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@tends";
                value[0] = p.TenDS;
                return connect.GetData("DAUSACH_LOADMADAUSACH", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable DauSach_TraCuu()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("DauSach_TraCuu");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            
        }
        public DataTable timDauSachDayDu(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@search";
                value[0] = dsDTO.TenDS;
                return connect.GetData("DauSach_TimDayDu", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachTheoTheLoai(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@theloai";
                value[0] = dsDTO.MaTL;
                return connect.GetData("DauSach_TimTheoTheLoai", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachTheoTheLoai_DayDu(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 2;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@theloai";
                value[0] = dsDTO.MaTL;
                name[1] = "@search";
                value[1] = dsDTO.TenDS;
                return connect.GetData("DauSach_TimTheoTheLoai_DayDu", name, value, 2);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachTheoTheLoai_TenDS(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 2;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@theloai";
                value[0] = dsDTO.MaTL;
                name[1] = "@search";
                value[1] = dsDTO.TenDS;                
                return connect.GetData("DauSach_TimTheoTheLoai_TenDS", name, value, 2);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachDayDu_TenDS(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 1;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@search";
                value[0] = dsDTO.TenDS;
                return connect.GetData("DauSach_TimDayDu_TenDS", name, value, 1);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachTheoTheLoai_TenTG(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 2;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@theloai";
                value[0] = dsDTO.MaTL;
                name[1] = "@search";
                value[1] = dsDTO.MaTG;
                return connect.GetData("DauSach_TimTheoTheLoai_TacGia", name, value, 2);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachDayDu_TenTG(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 1;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@search";
                value[0] = dsDTO.MaTG;
                return connect.GetData("DauSach_TimDayDu_TacGia", name, value, 1);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachTheoTheLoai_TenNXB(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 2;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@theloai";
                value[0] = dsDTO.MaTL;
                name[1] = "@search";
                value[1] = dsDTO.MaNXB;
                return connect.GetData("DauSach_TimTheoTheLoai_NXB", name, value, 2);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable timDauSachDayDu_TenNXB(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparammater = 1;
                string[] name = new string[Nparammater];
                object[] value = new object[Nparammater];
                name[0] = "@search";
                value[0] = dsDTO.MaNXB;
                return connect.GetData("DauSach_TimDayDu_NXB", name, value, 1);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int nhap(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 8;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@mads";
                value[0] = dsDTO.MaDS;
                name[1] = "@tends";
                value[1] = dsDTO.TenDS;
                name[2] = "@matl";
                value[2] = dsDTO.MaTL;
                name[3] = "@matg";
                value[3] = dsDTO.MaTG;
                name[4] = "@manxb";
                value[4] = dsDTO.MaNXB;
                name[5] = "@namxb";
                value[5] = dsDTO.NamXB;
                name[6] = "@trigia";
                value[6] = dsDTO.TriGia;
                name[7] = "@trangthai";
                value[7] = dsDTO.TrangThai;
                return connect.UpdateData("DauSach_InsertUpdate", name, value, Nparamater);

            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int Xoa(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@MaDS";
                value[0] = dsDTO.MaDS;
                return connect.UpdateData("DauSach_Xoa", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoadDuLieuCotMaDS(DauSachDTO dsDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@mads";
                value[0] = dsDTO.MaDS;
                return connect.GetData("DauSach_LoadDuLieuCotMaDS", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
